/*****************************************************************************
State of Aadhaar Survey 2017-2018

Title: 8_NREGA_pub.do
Author: IDinsight
Contact: stateofaadhaar@idinsight.org
Date: 29 August 2018
Data: "SOA2018_nonroster_cleaned_gen.dta"
User-written commands: estout (ssc install estout if not installed)
Description: 	This .do file conducts analysis for the NREGA section and
				produces output tables in "8_NREGA.rtf".

Contents:
	
	1. Analysis using non roster data
		- Survey set up
		- Tabulations / Proportions / Means
	
Missing data code:
	.r = refused
	.d = don't know	
*****************************************************************************/

	
* Setting up
	
	version 14
	capture log close
	clear all
	mac drop _all
	set more off
	
	* Please replace "..." below with the correct file path on your computer
	if "`c(os)'"=="MacOSX"{
		global dir "/Users/`c(username)'/.../SOA2018_data_release/"
		}
	else{
		global dir "C:/Users/`c(username)'/.../SOA2018_data_release/"
		}

/*****************************************************************************
1. Analysis using non roster data
*****************************************************************************/

	*** Survey set up

		cd "${dir}/Data_sets/"
		use "SOA2018_nonroster_cleaned_gen.dta", clear

		drop hh_id
		rename master_key hh_id 
		svyset district_id [pweight=weight_resp_adj] || AC_id || ps_id || hh_id || _n
		cd "${dir}/Output_tables/"
		

	***  Tabulations / Proportions / Means
		
		*****************************************************************
		* Q.1 How many job cards does the household have? 
		*****************************************************************
		
			eststo: estpost svy: tab jobcard_num_c, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (jobcard_num_c ==.d | jobcard_num_c ==.r)
			estadd scalar missing  = r(N)
			count if (jobcard_num_c ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab jobcard_num_c if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (jobcard_num_c ==.d | jobcard_num_c ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (jobcard_num_c ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.1 Number of NREGA job cards held by household (among all households surveyed)") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates.") ///
			replace 
			
			eststo clear
		
		*****************************************************************************
		* Q.2 Is the NREGA job card seeded to Aadhaar?
		*****************************************************************************
		
			eststo: estpost svy: tab nrega_ad, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_ad ==.d | nrega_ad ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_ad ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_ad if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_ad ==.d | nrega_ad ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_ad ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.2 Percentage of respondents whose Aadhaar is seeded with their NREGA job card (among those who have a job card)") ///	
			nostar ///
			coeflabels(0 "No" 1 "Yes") ///			
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear 
			
		******************************************************************************************
		* Q.3 Did the household member always get work when they were interested in the 9 months?
		******************************************************************************************
		
			eststo: estpost svy: tab work_opp, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (work_opp ==.d | work_opp ==.r)
			estadd scalar missing  = r(N)
			count if (work_opp ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab work_opp if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (work_opp ==.d | work_opp ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (work_opp ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.3 Percentage of respondents who were able to work when they were interested (among those who had a job card and were interested in working) ") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear
		
		*****************************************************************************
		* Q.4 Do you receive your wages directly in your bank account? 
		*****************************************************************************
			
			eststo: estpost svy: tab nrega_dbt, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_dbt ==.d | nrega_dbt ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_dbt ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_dbt if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_dbt ==.d | nrega_dbt ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_dbt ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.4 Percentage of respondents who received their wages directly in their bank account (among those who had worked in the last nine months)") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear
			
		************************************************************************************************************************
		* Q.5 Overall, how easy or difficult do you find the process of receiving your benefits directly in your bank account?
		************************************************************************************************************************
		
			eststo: estpost svy: tab nrega_ease, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_ease ==.d | nrega_ease ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_ease ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_ease if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_ease ==.d | nrega_ease ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_ease ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.5 Perceived ease of the process for receiving wages directly in one's bank account (among those who receive wages directly in their bank accounts)") ///	
			nostar ///
			coeflabels(2 "Easier" 3 "Neither easier nor more difficult" 4 "More difficult") ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear
			
		*****************************************************************************
		* Q.6 Have you ever failed to receive wages for work that you have done?
		*****************************************************************************
			
			eststo: estpost svy: tab nrega_wage_fail, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_wage_fail ==.d | nrega_wage_fail ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_wage_fail ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_wage_fail if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_wage_fail ==.d | nrega_wage_fail ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_wage_fail ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.6 Percentage of respondents who failed to receive wages for their work (among those who had worked in the last nine months)") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear
		
		*****************************************************************************
		* Q.7 Were wages ever delayed by more than 15 days?
		*****************************************************************************
		
			eststo: estpost svy: tab nrega_delay, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_delay ==.d | nrega_delay ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_delay ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_delay if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_delay ==.d | nrega_delay ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_delay ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.7 Percentage of respondents whose wage was delayed by more than 15 days (among those who had worked in the last nine months)") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			) ///
			append 
			
			eststo clear
		
		*********************************************************************************
		* Q.8 Respondents whose name was removed from the list because of Aadhaar seeding
		*********************************************************************************
		
			eststo: estpost svy: tab nrega_problems_1, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_problems_1 ==.d | nrega_problems_1 ==.r)
			estadd scalar missing  = r(N)
			count if (nrega_problems_1 ==.e) 
			estadd scalar er  = r(N)
				forvalues i = 1/3 {
			display `i' 
			eststo: estpost svy: tab nrega_problems_1 if state == `i', percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (nrega_problems_1 ==.d | nrega_problems_1 ==.r) & state == `i'
			estadd scalar missing  = r(N)
			count if (nrega_problems_1 ==.e) & state == `i'
			estadd scalar er  = r(N)
				}
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.8 Percentage of respondents whose name was removed from the NREGA list due to Aadhaar seeding (among those who had worked at least once in the last nine months)") ///	
			nostar ///
			nonumbers ///
			mtitles ("All three states" "Andhra Pradesh" "Rajasthan" "West Bengal") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates.") ///
			append 
			
			eststo clear
		
		
		****************************************************************************************************************
		* Q.9 Exclusion due to Aadhaar wherein a respondent was unable to withdraw his/her wages in cash from a MicroATM
		****************************************************************************************************************
		* This is only applicable to the state of Andhra Pradesh 
		
			eststo: estpost svy: tab exclusion_microATM if state == 1, percent nototal ci
			estadd matrix cil = e(lb)
			estadd matrix ciu = e(ub)
			count if (exclusion_microATM ==.d | exclusion_microATM ==.r) & state == 1
			estadd scalar missing  = r(N)
			count if (exclusion_microATM ==.e) & state == 1
			estadd scalar er  = r(N)
			
			esttab using "8_NREGA.rtf", ///
			compress ///
			collabels(none) ///
			eqlabels(none) ///
			label ///
			modelwidth(0) ///
			incelldelimiter(-) ///
			cells(b(fmt(1)) "cil & ciu") ///
			title ("Table 8.9 Percentage of respondents who were unable to withdraw their NREGA wages in cash in Andhra Pradesh (among those who used a microATM to withdraw their wages)") ///	
			nostar ///
			nonumbers ///
			mtitles ("Andhra Pradesh") ///
			nogaps ///
			stats(N missing, fmt(0) label("Number of observations" "Number of missing observations (don't know / refused)")) ///
			nonotes ///
			addnotes("Notes: 95% confidence intervals are under point estimates." ///
			"This question was asked to respondents in Andhra Pradesh only. In our survey, we asked respondents if they were unable to withdraw their wages in cash from a microATM. If they were unable to do so, we asked a follow up question on the alternative mechanisms that they used. 'Unable to withdraw wages' in this case includes only those respondents who were unable to withdraw via any medium (microATM or otherwise).") ///
			append 
			
			eststo clear
		
